from MySQLPool import *

table_name="WECHAT_RECEIVE_MESSAGE"
column_name_list="ID,RECEIVE_OBJECT_ID,MESSAGE_SENDER_NUMBER,MESSAGE_SENDER_NAME,MESSAGE_RECEIVER_NUMBER,MESSAGE_RECEIVER_NAME,MESSAGE,FILE_URL,SEND_TIME,RECEIVE_TIME,CREATE_USER,CREATE_TIME,UPDATE_USER,UPDATE_TIME,LOGIC_DEL_FLAG"

# def queryByWechatUserId(wechatUserId):
#     if wechatUserId is not None:
#         with dbpool.get_connection() as connection:
#             receiveObjectList=connection.query("select * from {table_name} where LOGIC_DEL_FLAG=0 and BELONG_WECHAT_USER_ID = %(wechatUserId)s",{"wechatUserId":wechatUserId})
#             connection.close()
#             if receiveObjectList is None:
#                 return None
#             else:
#                 return receiveObjectList
#     return None


def insert(receiveObjectMessage):
    rows_affected=0
    if receiveObjectMessage is not None:
        with dbpool.get_connection() as connection:
            insert_query = "insert into {table_name} ({column_name_list}) values (null,%(RECEIVE_OBJECT_ID)s,%(MESSAGE_SENDER_NUMBER)s,%(MESSAGE_SENDER_NAME)s,%(MESSAGE_RECEIVER_NUMBER)s,%(MESSAGE_RECEIVER_NAME)s,%(MESSAGE)s,%(FILE_URL)s,%(SEND_TIME)s,%(RECEIVE_TIME)s,%(CREATE_USER)s,%(CREATE_TIME)s,%(UPDATE_USER)s,%(UPDATE_TIME)s,0)"
            rows_affected = connection.execute(insert_query, receiveObjectMessage)

    return rows_affected